package com.aj.activity.adapter;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aj.activity.R;
import com.aj.databases.entry.CmtInfo;

public class CommontTextAdapter extends BaseAdapter {

	private List<CmtInfo> cmtInfoList;

	private Context context;

	private HashMap<Integer, View> viewCache = new HashMap<Integer, View>();

	public CommontTextAdapter(Context context, List<CmtInfo> cmtInfoList) {
		this.context = context;
		this.cmtInfoList = cmtInfoList;
	}

	@Override
	public int getCount() {
		return cmtInfoList.size();
	}

	@Override
	public Object getItem(int position) {
		return cmtInfoList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	class ViewHodler {
		TextView commont_text;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView = viewCache.get(position);
		ViewHodler viewHodler = null;
		CmtInfo cmtInfo = cmtInfoList.get(position);
		if (convertView == null) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.item_commont_text, null);
			viewHodler = new ViewHodler();
			viewHodler.commont_text = (TextView) convertView
					.findViewById(R.id.commont_text);
		} else {
			viewHodler = (ViewHodler) convertView.getTag();
		}
		if (cmtInfo.getIsReply().equals("0")) {
			viewHodler.commont_text
					.setText((cmtInfo.getReplyUserCallName() == null ? "我"
							: cmtInfo.getReplyUserCallName())
							+ "("
							+ cmtInfo.getReplyUserNickName()
							+ ") 回复 "
							+ ((cmtInfo.getCmtUserCallName() == null) ? "我"
									: cmtInfo.getCmtUserCallName())
							+ "("
							+ cmtInfo.getCmtUserNickName()
							+ "):"
							+ cmtInfo.getCmtContent());
		} else {
			viewHodler.commont_text
					.setText((cmtInfo.getCmtUserCallName() == null ? "我"
							: cmtInfo.getCmtUserCallName())
							+ "("
							+ cmtInfo.getCmtUserNickName()
							+ "):"
							+ cmtInfo.getCmtContent());
		}
		return convertView;
	}
}
